<template>
  <div>
    <div class="nav-bar" :class="{' is_fixed': isFixed }" :style="opacityStyle">
      <div class="container">
        <div class="pro-title">{{title}}</div>
        <div class="pro-param">
          <a href="javascript:;">概述</a><span>|</span>
          <a href="javascript:;">参数</a><span>|</span>
          <a href="javascript:;">用户评价</a>
          <slot name="buy"></slot>
          <slot name="bu"></slot>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
export default {
  name: 'ProductParams',
props:["title"],
  data() {
    return {
      isFixed: false,
      opacityStyle: {
        opacity: 0.5
      }
    }
  },

  mounted() {
    window.addEventListener('scroll', this.initHeight)
  },

  methods: {
    initHeight() {
      const top = document.documentElement.scrollTop
      if (top > 152) {
        this.isFixed = true
        let opacity = top / 356
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
      } else {
        this.isFixed = false
      }
    }
  },
  destroyed() {
    //   n,true添加事件时) 只监听 “捕获事件”  当第三个参数为false时  只监听  冒泡事件
    window.removeEventListener('scroll', this.initHeight, false)
  }
}
</script>

<style lang="scss" scoped>
@import '../../assets//scss/config';
@import '../../assets//scss/mixin';
.h {
  height: 1000px;
}
.nav-bar {
  height: 70px;
  line-height: 70px;
background: #fff;
  &.is_fixed {
   @include position(fixed)  height: 70px;
  line-height: 70px;
    box-shadow: 0 5px 5px $colorE;
     z-index: 10;
  }

  .container {
    @include flex();
    .pro-title {
      font-size: $fontH;
      color: $colorB;
      font-weight: bold;
    }
    .pro-param {
      font-size: $fontJ;
      span {
        margin: 0 10px;
      }
      a {
        color: $colorC;
      }
    }
  }
}
</style>
